/*
	 * Click event for create button
	 * Creates new value of data being displayed in Modal form
	 * Refreshes data table on successful creation
	 * 
	 * Calls 
	 * refreshMyTable()
	 * 
	 * converter()
	 * <SerializedArray> - Serialized Array of Form Data
	 */
	    $("#request").click(function(){
//	    	formData = ($('#signUpForm').serializeArray());
//alert(converter(formData));
	    	$('#signUpForm').validate({
	            rules: {
	            	cfName: {
	                    maxlength: 15,
	                    required: true
	                },
	                cfMobile: {
	                    maxlength: 15,
	                    required: true
	                },
	                cfEmail: {
	                    maxlength: 15,
	                    required: true
	                },
	                cfReason: {
	                    maxlength: 15,
	                    required: true
	                },
	                cfType: {
	                    maxlength: 15,
	                    required: true
	                },
	               
	                
	            },
	            highlight: function(element) {
	                $(element).closest('.form-group').addClass('has-error');
	            },
	            unhighlight: function(element) {
	                $(element).closest('.form-group').removeClass('has-error');
	            },
	            errorElement: 'span',
	            errorClass: 'help-block',
	            errorPlacement: function(error, element) {
	                if(element.parent('.input-group').length) {
	                    error.insertAfter(element.parent());
	                } else {
	                    error.insertAfter(element);
	                }
	            }
	        });

    	if($('#signUpForm').valid()) {
		formData = ($('#signUpForm').serializeArray());
 
		$.ajax({
		    url : 'http://localhost:8080/easyskool/rest/userauthservice/insertRequest',
			type : 'POST',
			async: false,
			data : '{"user":"sumit","fields":'+ converter(formData)+ '}',
			dataType : 'json',
			contentType : "application/json; charset=utf-8",
			success : function(data,testStatus,jqXHR) {
				var json = jQuery.parseJSON(jqXHR.responseText);
					if(json.responseMessage == "success"){
						//window.location = "http://localhost:8080/easyskool/WebPages/Masters/MasterSectionHome.jsp";
						alert("Record Successfully Stored..");
					} else	{
						alert("Error: ! "+ jqXHR.responseText);
					}
			},
		error : function(data,testStatus,jqXHR) {
			alert("error occured");
		}
	    });
    	}
	});
    